package com.xiaomaoguai.java.concurrent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/*
 * @Description :
 * @FileName: ConcurrentMap.java
 * @Author :WeiHui.Zhang
 * @Data : 2014年12月15日 上午9:20:02
 * @Version:1.0.0
 */
public class ConcurrentMap {

	private static final Map<String, Long> WORDCOUNTS = new ConcurrentHashMap<>();

	public static long increase(String word) {
		Long oldValue = WORDCOUNTS.get(word);
		Long newValue = (oldValue == null) ? 1L : oldValue + 1;
		WORDCOUNTS.put(word, newValue);
		return newValue;
	}

	public static void main(String[] args) {
		// int a = 1 << 3;
		// String binaryString = Integer.toBinaryString(a);
		// System.out.println(binaryString);
		// System.out.println(a);

		WORDCOUNTS.put("1", 1L);
		WORDCOUNTS.put("2", 2L);
		WORDCOUNTS.put("3", 3L);

		increase("1");
		long increase = increase("1");

		System.out.println(increase);
	}
}
